Imports DAL
Imports MyClasses
Imports System.Configuration

Public Class frmDoctor
    Dim _intDoctorID As Integer
    Dim intAddress As Integer
    Dim address(0) As CAddress
    'Dim flag As Boolean
    Dim blnFlagAddType As Boolean
    Dim blnCountryFlag As Boolean
    Dim blnStateFlag As Boolean
    Dim blnCityFlag As Boolean
    Dim updtAddress(0) As CAddress

    Private Sub cmbRefType_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbRefType.DropDownClosed
        If cmbRefType.SelectedValue.ToString = "A" Then
            lblPercent.Text = ConfigurationManager.AppSettings("Currency")
        Else
            lblPercent.Text = "%"
        End If
    End Sub

    Private Sub cmbRefType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbRefType.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then txtRefAmt.Focus()
    End Sub

    Private Sub cmbTitle_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbTitle.KeyDown
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtLname.Focus()
            Else
                txtFname.Focus()
            End If
        End If
    End Sub

    'Divya@13/02/2008 : Added for Tab key sequence for Name
    Private Sub cmbTitle_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbTitle.Leave
        If Keys.Tab Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtLname.Focus()
                txtLname.Tag = txtLname.Text
            Else
                txtFname.Focus()
                txtFname.Tag = txtFname.Text
            End If
        End If
    End Sub

    Private Sub txtFname_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFname.GotFocus
        If btnSave.Text = "&Save" Then If txtFname.Text = txtFname.Tag Then txtFname.Text = ""
    End Sub

    Private Sub txtFname_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFname.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            txtMname.Focus()
        Else
            If e.Shift = True Then
                If e.KeyCode = Keys.OemQuotes Then
                    e.SuppressKeyPress = True
                End If
                If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                    e.SuppressKeyPress = True
                End If
            End If
        End If
    End Sub

    Private Sub txtLname_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLname.GotFocus
        If btnSave.Text = "&Save" Then If txtLname.Text = txtLname.Tag Then txtLname.Text = ""
    End Sub

    Private Sub txtLname_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLname.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtFname.Focus()
            Else
                txtDrDispName.Focus()
            End If
        Else
            If e.Shift = True Then
                If e.KeyCode = Keys.OemQuotes Then
                    e.SuppressKeyPress = True
                End If
                If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                    e.SuppressKeyPress = True
                End If
            End If
        End If
    End Sub

    'Divya@13/02/2008 : Added for Tab key sequence for Name
    Private Sub txtLname_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLname.Leave
        If Keys.Tab Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtFname.Focus()
            Else
                txtDrDispName.Focus()
            End If
        End If
    End Sub

    Private Sub txtDrDispName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDrDispName.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            cmbQual.Focus()
        Else
            If e.Shift = True Then
                If e.KeyCode = Keys.OemQuotes Or e.KeyCode = Keys.OemPeriod Then
                    e.SuppressKeyPress = True
                End If
                If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                    e.SuppressKeyPress = True
                End If
            End If
        End If
    End Sub

    Private Sub txtMname_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMname.GotFocus
        If btnSave.Text = "&Save" Then If txtMname.Text = txtMname.Tag Then txtMname.Text = ""
    End Sub

    Private Sub txtMname_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMname.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtDrDispName.Focus()
            Else
                txtLname.Focus()
            End If
        Else
            If e.Shift = True Then
                If e.KeyCode = Keys.OemQuotes Or e.KeyCode = Keys.OemPeriod Then
                    e.SuppressKeyPress = True
                End If
                If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                    e.SuppressKeyPress = True
                End If
            End If
        End If
    End Sub

    Private Sub txtMname_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMname.Leave
        'Divya@13/02/2008 : Added for Tab key sequence for Name
        If Keys.Tab Then
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtDrDispName.Focus()
            Else
                txtLname.Focus()
            End If
        End If
    End Sub

    Private Sub cmbQual_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbQual.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbSpecial.Focus()
    End Sub

    Private Sub txtRefAmt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRefAmt.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbHospName.Focus()
        If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
        e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM", False)
    End Sub

    Private Sub cmbAddrType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbAddrType.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then txtAddr1.Focus()
    End Sub

    Private Sub txtaddr1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtAddr1.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            cmbCountry.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALFTEXT", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

    Private Sub cmbcity_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbCity.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then txtPinCode.Focus()
    End Sub

    Private Sub txtPincode_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPinCode.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then txtPhone1.Focus()
        If e.KeyCode = Keys.Shift Then e.SuppressKeyPress = True
        e.SuppressKeyPress = Not BCommon.ValidateMiscell(e.KeyCode, "PHONE")
    End Sub

    Private Sub cmbstate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbState.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbCity.Focus()
    End Sub

    Private Sub cmbCountry_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbCountry.GotFocus
        If cmbCountry.SelectedValue = Nothing Then
            cmbCountry.SelectedValue = ConfigurationManager.AppSettings("Country")
        End If
    End Sub

    Private Sub cmbcountry_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbCountry.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbState.Focus()
    End Sub

    Private Sub txtphone1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone1.KeyDown
        Try
            'Rahul_ITS@2007113 : Add following line
            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtPhone2.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtphone1_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
    Private Sub txtPhone1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone1.KeyUp
        Try
            If (BCommon.IsInteger(txtPhone1.Text) = False) Then txtPhone1.Focus() : txtPhone1.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtPhone1_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtphone2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone2.KeyDown
        Try
            'Rahul_ITS@2007113 : Add following line
            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtFax.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtphone2_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
    Private Sub txtPhone2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPhone2.KeyUp
        Try
            If (BCommon.IsInteger(txtPhone2.Text) = False) Then txtPhone2.Focus() : txtPhone2.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtPhone2_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtfax_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFax.KeyDown
        Try
            'Rahul_ITS@2007113 : Add following line
            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then txtEmail.Focus()
            If e.Shift = True Then
                If (e.KeyCode >= 48 And e.KeyCode <= 48 + 10) Or (e.KeyCode >= 96 And e.KeyCode <= 96 + 10) Then
                    e.SuppressKeyPress = True
                    Me.Cursor = Cursors.Default
                    Exit Sub
                End If
            End If
            If BCommon.ValidateMiscell(e.KeyCode, "QTY") = False Then e.SuppressKeyPress = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtfax_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
    Private Sub txtfax_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFax.KeyUp
        Try
            If (BCommon.IsInteger(txtFax.Text) = False) Then txtFax.Focus() : txtFax.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtfax_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtemail_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEmail.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            txtWebSite.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALFTEXT", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

    Private Sub txtwebsite_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtWebSite.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            btnSave.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALFTEXT", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

    Private Sub cmbHospName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbHospName.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbAddrType.Focus()
    End Sub

    Private Sub txtShortName_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtShortName.KeyDown
        'Rahul_ITS@2007113 : Add following line
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then
            cmbAddrType.Focus()
        Else
            If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                e.SuppressKeyPress = True
            End If
        End If
    End Sub

    Private Function ValidateData() As Boolean
        Try
            If Trim(txtFname.Text) = "" Or Trim(txtFname.Text) = "<First Name>" Then
                BCommon.ShowMsgError(10011)
                txtFname.Focus()
                Me.Cursor = Cursors.Default
                Return False
            End If

            If Trim(txtLname.Text) = "" Or Trim(txtLname.Text) = "<Last Name>" Then
                BCommon.ShowMsgError(10012)
                txtLname.Focus()
                Me.Cursor = Cursors.Default
                Return False
            End If

            If Trim(txtEmail.Text) <> "" Then
                If BCommon.ValidateEmailID(txtEmail.Text) = False Then
                    txtEmail.Focus()
                    Me.Cursor = Cursors.Default
                    Return False
                End If
                ValidateData = True
            End If

            If Trim(txtWebSite.Text) <> "" Then
                If BCommon.ValidateWebAdd(txtWebSite.Text) = False Then
                    txtWebSite.Focus()
                    Me.Cursor = Cursors.Default
                    Return False
                End If
                ValidateData = True
            End If

            If (Trim(txtPhone1.Text) <> "" And Trim(txtPhone2.Text) <> "") _
            Or (Trim(txtPhone1.Text) <> "" And Trim(txtFax.Text) <> "") _
            Or (Trim(txtPhone2.Text) <> "" And Trim(txtFax.Text) <> "") Then
                If Trim(txtPhone1.Text) = Trim(txtPhone2.Text) Then
                    BCommon.ShowMsgError(10002)
                    txtPhone2.Focus()
                    Me.Cursor = Cursors.Default
                    Return False
                ElseIf Trim(txtPhone1.Text) = Trim(txtFax.Text) Then
                    BCommon.ShowMsgError(10008)
                    txtFax.Focus()
                    Me.Cursor = Cursors.Default
                    Return False               
                ElseIf Trim(txtPhone2.Text) = Trim(txtFax.Text) Then
                    BCommon.ShowMsgError(10001)
                    txtPhone2.Focus()
                    Me.Cursor = Cursors.Default
                    Return False
                End If
            End If
            Me.Cursor = Cursors.Default
            Return True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ValidateData")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    'To clear all the Text or Combo Control
    Private Sub ClearData()
        Try
            txtDoctorID.Text = BCommon.GetSequentialID("DOCTOR")
            txtDrDispName.Text = ""
            btnSave.Text = "&Save"
            btnDelete.Enabled = False
            If cmbQual.Items.Count > 0 Then cmbQual.SelectedIndex = 0 : cmbQual.Tag = cmbQual.SelectedValue
            If cmbHospName.Items.Count > 0 Then cmbHospName.SelectedIndex = 0 : cmbHospName.Tag = cmbHospName.SelectedValue
            If cmbRefType.Items.Count > 0 Then cmbRefType.SelectedIndex = 0 : cmbRefType.Tag = cmbRefType.SelectedValue
            If cmbAddrType.Items.Count > 0 Then cmbAddrType.SelectedIndex = 0 : cmbAddrType.Tag = cmbAddrType.SelectedValue
            If CMBSPECIAL.Items.Count > 0 Then CMBSPECIAL.SelectedIndex = 0 : CMBSPECIAL.Tag = CMBSPECIAL.SelectedValue
            txtDrDispName.Text = ""
            txtRefAmt.Text = ""
            txtFname.Tag = "<First Name>"
            txtMname.Tag = "<Middle Name>"
            txtLname.Tag = "<Last Name>"
            txtFname.Text = txtFname.Tag
            txtMname.Text = txtMname.Tag
            txtLname.Text = txtLname.Tag
            cmbTitle.SelectedValue = Replace(ConfigurationManager.AppSettings("Title"), ".", "")
            cmbTitle.Tag = cmbTitle.SelectedValue

            cmbTitle.Tag = cmbTitle.SelectedValue
            If ConfigurationManager.AppSettings("NameSeq") = "TLFM" Then
                txtLname.Location = New Point(225, 57)
                txtFname.Location = New Point(344, 57)
                txtMname.Location = New Point(462, 57)
            End If
            lblPercent.Text = ConfigurationManager.AppSettings("Currency")
            Call clear_addr()
            Call ClearAddress()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Display the data while the form is loaded
    Private Sub DisplayData()
        Try
            Dim dtbCountry As New DataTable
            Dim dtbHospital As New DataTable
            Me.Text = "Doctor"
            Call ClearData()
            dtbCountry = DAddress.GetCountry()
            dtbHospital = BHospital.GetHospitalName()
            BCommon.SetComboValues(cmbQual, "QUALIFICATION")
            BCommon.SetComboValues(cmbRefType, "AMTTYPE")
            BCommon.SetComboValues(cmbHospName, dtbHospital, "HospitalID", "Name")
            BCommon.SetComboValues(cmbTitle, "TITLE")
            BCommon.SetComboValues(cmbAddrType, "ADDRESS_TYPE")
            BCommon.SetComboValues(cmbCountry, dtbCountry, "CountryCD", "Description")
            BCommon.SetComboValues(CMBSPECIAL, "DOCTOR_SPECIALITY")
            'flag = True
            txtFname.Text = txtFname.Tag
            txtMname.Text = txtMname.Tag
            txtLname.Text = txtLname.Tag
            cmbTitle.Tag = cmbTitle.SelectedValue
            cmbTitle.SelectedValue = Replace(BCommon.GetConfigValues("Title"), ".", "")
            txtDrDispName.Tag = txtDrDispName.Text
            cmbQual.Tag = cmbQual.SelectedValue
            CMBSPECIAL.Tag = CMBSPECIAL.SelectedValue
            cmbRefType.Tag = cmbRefType.SelectedValue
            txtRefAmt.Tag = Trim(txtRefAmt.Text)
            cmbHospName.Tag = cmbHospName.SelectedValue
            txtShortName.Tag = Trim(txtShortName.Text)
            cmbCountry.SelectedIndex = -1
            cmbState.SelectedIndex = -1
            cmbCity.SelectedIndex = -1
            If txtAddr1.TextLength = txtAddr1.MaxLength Then
            End If
            Call SetcontrolTag()
            BCommon.SetTextReadOnly(txtDoctorID)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "DisplayData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    ' Assign values to the CDoctor Object
    Private Function SetData() As CDoctor
        Dim objDoctor As New CDoctor
        Try
            With objDoctor
                .doctorID = _intDoctorID
                .doctorSeqID = Trim(txtDoctorID.Text)
                .qualification = cmbQual.SelectedValue
                .specialisation = CMBSPECIAL.SelectedValue
                .RefAmount = Trim(txtRefAmt.Text)
                .RefType = cmbRefType.SelectedValue
            End With

            With objDoctor.person
                If btnSave.Text = "&Save" Then
                    .Title = cmbTitle.SelectedValue
                    .First_Name = IIf(Trim(txtFname.Text) <> txtFname.Tag, Trim(txtFname.Text), "")
                    .Middle_Name = IIf(Trim(txtMname.Text) <> txtMname.Tag, Trim(txtMname.Text), "")
                    .Last_Name = IIf(Trim(txtLname.Text) <> txtLname.Tag, Trim(txtLname.Text), "")
                    .Display_Name = Trim(txtDrDispName.Text)
                Else
                    .Title = cmbTitle.SelectedValue
                    .First_Name = Trim(txtFname.Text)
                    .Middle_Name = Trim(txtMname.Text)
                    .Last_Name = Trim(txtLname.Text)
                    .Display_Name = Trim(txtDrDispName.Text)
                End If
            End With

            With objDoctor.hospital
                If cmbHospName.SelectedValue <> Nothing Then
                    .HospitalID = cmbHospName.SelectedValue
                Else
                    .HospitalName = cmbHospName.Text
                    .Ref_type = cmbRefType.SelectedValue
                    .HospShortName = Trim(txtShortName.Text)
                End If
            End With
            Return objDoctor
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetData")
            Me.Cursor = Cursors.Default
            Return Nothing
        End Try
    End Function

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Me.Cursor = Cursors.WaitCursor
        If SaveData() Then
            Call DisplayData()
        End If
        Me.Cursor = Cursors.Default
    End Sub

    'Save and Update the Information
    Private Function SaveData() As Boolean
        Dim objDoctor As CDoctor
        Dim blnResult As Boolean
        Try
            If ValidateData() = False Then Me.Cursor = Cursors.Default : Exit Function
            objDoctor = SetData()
            If btnSave.Text = "&Save" Then
                blnResult = DDoctor.SaveDoctor(objDoctor, "S", SetAddress())
                If blnResult = True Then BCommon.ShowMsgError(3) Else BCommon.ShowMsgError(4)
            Else
                blnResult = DDoctor.SaveDoctor(objDoctor, "U", SetAddress())
                If blnResult = True Then
                    BCommon.ShowMsgError(5)
                    btnSave.Text = "&Save"
                    btnDelete.Enabled = False
                Else
                    BCommon.ShowMsgError(4)
                End If
            End If
            Return blnResult
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SaveData")
            Me.Cursor = Cursors.Default
            Return False
        End Try
    End Function

    Private Sub cmbAddrType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbAddrType.SelectedIndexChanged
        If blnFlagAddType = False Then Me.Cursor = Cursors.Default : Exit Sub
        Try
            If isAddressChanged() = 1 Then Call SetAddress(intAddress)
            Call clear_addr()
            intAddress = cmbAddrType.SelectedIndex
            If intAddress >= 0 Then
                Call Getaddress(intAddress)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cmbAddrType_SelectedIndexChanged")
            Me.Cursor = Cursors.Default
        End Try

    End Sub

    ' Set Address according to the Address Type selected
    Private Function SetAddress(ByVal IntAddress As Integer) As CAddress()
        Try
            Dim intAddressID As Integer = 0
            If Not IsNothing(address(IntAddress)) Then
                intAddressID = address(IntAddress).AddressID
            End If
            address(IntAddress) = New CAddress
            address(IntAddress).AddressID = intAddressID
            With address(IntAddress)
                .AddressType = cmbAddrType.Items(IntAddress).item(0).ToString()
                .Description1 = Trim(txtAddr1.Text)
                .Country = cmbCountry.SelectedValue
                .State = cmbState.SelectedValue
                .PinCode = IIf(Trim(txtPinCode.Text) <> "", Trim(txtPinCode.Text), 0)
                If cmbCity.SelectedValue = Nothing Then
                    If cmbCity.Text <> "" Then
                        .City = DAddress.SaveCity(.State, .Country, cmbCity.Text, .PinCode)
                    End If
                Else
                    .City = cmbCity.SelectedValue
                End If
                .PhoneNo1 = Trim(txtPhone1.Text)
                .PhoneNo2 = Trim(txtPhone2.Text)
                .Fax = IIf(Trim(txtFax.Text) <> "", Trim(txtFax.Text), 0)
                .EmailID = Trim(txtEmail.Text)
                .WebSiteAddress = Trim(txtWebSite.Text)
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetAddress(intAddressID)")
            Me.Cursor = Cursors.Default
        End Try
        Return address
    End Function

    'Set the Address Information from controls to Address array
    Private Function SetAddress() As CAddress()
        Try
            Dim intAddressID As Integer = 0
            If Not IsNothing(address(cmbAddrType.SelectedIndex)) Then
                intAddressID = address(cmbAddrType.SelectedIndex).AddressID
            End If
            If isAddressChanged() = 1 Then
                address(cmbAddrType.SelectedIndex) = New CAddress
                address(cmbAddrType.SelectedIndex).AddressID = intAddressID
                With address(cmbAddrType.SelectedIndex)
                    .AddressType = Trim(cmbAddrType.SelectedValue)
                    .Description1 = Trim(txtAddr1.Text)
                    .Country = cmbCountry.SelectedValue
                    .State = cmbState.SelectedValue
                    .PinCode = IIf(Trim(txtPinCode.Text) <> "", Trim(txtPinCode.Text), 0)
                    If cmbCity.SelectedValue = Nothing Then
                        If cmbCity.Text <> "" Then
                            .City = DAddress.SaveCity(.State, .Country, cmbCity.Text, .PinCode)
                        End If
                    Else
                        .City = cmbCity.SelectedValue
                    End If
                    .PhoneNo1 = Trim(txtPhone1.Text)
                    .PhoneNo2 = Trim(txtPhone2.Text)
                    .Fax = IIf(Trim(txtFax.Text) <> "", Trim(txtFax.Text), 0)
                    .EmailID = Trim(txtEmail.Text)
                    .WebSiteAddress = Trim(txtWebSite.Text)
                End With
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetAddress")
            Me.Cursor = Cursors.Default
        End Try
        Return address
    End Function

    'Retrives Address from the database
    Private Sub Getaddress(ByVal intC As Integer)
        Try
            If IsNothing(address(intC)) Then
                Me.Cursor = Cursors.Default
                Exit Sub
            End If
            With address(intC)
                txtAddr1.Text = .Description1
                txtAddr1.Tag = .Description1
                cmbCountry.SelectedValue = .Country
                cmbCountry.Tag = .Country
                cmbState.SelectedValue = .State
                cmbState.Tag = .State
                cmbCity.SelectedValue = .City
                cmbCity.Tag = .City
                txtPinCode.Text = .PinCode
                txtPinCode.Tag = .PinCode
                txtPhone1.Text = .PhoneNo1
                txtPhone1.Tag = .PhoneNo1
                txtPhone2.Text = .PhoneNo2
                txtPhone2.Tag = .PhoneNo2
                txtFax.Text = IIf(.Fax = 0, "", .Fax)
                txtFax.Tag = IIf(.Fax = 0, "", .Fax)
                txtEmail.Text = .EmailID
                txtEmail.Tag = .EmailID
                txtWebSite.Text = .WebSiteAddress
                txtWebSite.Tag = .WebSiteAddress
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "Getaddress")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Displays the person information 
    Private Sub ViewPerson(ByVal personid As Integer)
        Dim dtsPerson As New DataSet
        Try
            dtsPerson = DDoctor.GetPerson(personid)
            With dtsPerson.Tables(0).Rows(0)
                cmbTitle.SelectedValue = .Item(0)
                cmbTitle.Tag = .Item(0)
                txtFname.Text = .Item(1)
                txtFname.Tag = .Item(1)
                txtMname.Text = .Item(2)
                txtMname.Tag = .Item(2)
                txtLname.Text = .Item(3)
                txtLname.Tag = .Item(3)
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ViewPerson")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Displays the Address Information of the corresponding doctor
    Private Sub ViewAddress(ByVal intPersonID As Integer)
        Dim dtbAddr As New DataTable
        Dim intc As Integer = 0
        Dim intCount, intAddrCount As Integer
        Try
            dtbAddr = DAddress.SearchAddress(intPersonID)
            For intAddrCount = 0 To dtbAddr.Rows.Count - 1
                'For Each row As DataRow In dtbAddr.Rows
                If IsNothing(dtbAddr.Rows(intc)) Then Me.Cursor = Cursors.Default : Exit Sub

                For intCount = 0 To cmbAddrType.Items.Count - 1
                    If cmbAddrType.DataSource.Rows(intCount).Item(0).ToString() = dtbAddr.Rows(intc).Item(0).ToString() Then
                        Me.Cursor = Cursors.Default
                        Exit For
                    End If
                Next
                With dtbAddr.Rows(intc)
                    address(intCount) = New CAddress
                    address(intCount).AddressType = .Item(0)
                    address(intCount).Description1 = .Item(1)
                    address(intCount).Description2 = .Item(2)
                    address(intCount).PinCode = .Item(3)
                    address(intCount).City = .Item(4)
                    address(intCount).State = .Item(5)
                    address(intCount).Country = .Item(6)
                    address(intCount).PhoneNo1 = .Item(7)
                    address(intCount).PhoneNo2 = .Item(8)
                    address(intCount).Fax = .Item(11)
                    address(intCount).EmailID = .Item(12)
                    address(intCount).WebSiteAddress = .Item(13)
                    address(intCount).AddressID = .Item(14)
                    intc = intc + 1
                End With
            Next
            If dtbAddr.Rows.Count > 0 Then
                If cmbAddrType.SelectedValue <> dtbAddr.Rows(0).Item(0) Then
                    blnFlagAddType = False
                    cmbAddrType.SelectedValue = dtbAddr.Rows(0).Item(0)
                    blnFlagAddType = True
                End If
                intAddress = cmbAddrType.SelectedIndex
                CCommon.CopyArray(address, updtAddress) 'copy address array to updatearray
                Call Getaddress(intAddress)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ViewAddress()")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    '   Clear the Address Controls
    Private Sub clear_addr()
        Try
            txtAddr1.Text = ""
            txtAddr1.Tag = ""
            cmbCountry.SelectedIndex = -1
            cmbCountry.Tag = Nothing
            cmbState.SelectedIndex = -1
            cmbState.Tag = Nothing
            cmbCity.SelectedIndex = -1
            cmbCity.Tag = Nothing
            txtPinCode.Text = ""
            txtPinCode.Tag = ""
            txtPhone1.Text = ""
            txtPhone1.Tag = ""
            txtPhone2.Text = ""
            txtPhone2.Tag = ""
            txtFax.Text = ""
            txtFax.Tag = ""
            txtEmail.Text = ""
            txtEmail.Tag = ""
            txtWebSite.Text = ""
            txtWebSite.Tag = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "clear_addr")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    '   Clear the Address Array
    Private Sub ClearAddress()
        Try
            Dim intCount As Integer
            intAddress = 0
            For intCount = 0 To address.Length - 1
                address(intCount) = Nothing
                updtAddress(intCount) = Nothing
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearAddress")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    '       Displays the State name according to the Country Name Selected
    Private Sub GetCountryState()
        Dim dtcountry As New DataTable
        Try

            dtcountry = DAddress.GetCountryStates(cmbCountry.SelectedValue)
            blnStateFlag = False
            BCommon.SetComboValues(cmbState, dtcountry, "StateCD", "Description")
            blnStateFlag = True
            If ConfigurationManager.AppSettings("Country") = cmbCountry.SelectedValue Then
                cmbState.SelectedValue = ConfigurationManager.AppSettings("State")
                cmbState.Refresh()
            Else
                cmbCity.Text = ""
                txtPinCode.Text = ""
                cmbState.Text = ""
            End If
            GetStateCity(cmbState.SelectedValue)

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetCountryState")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Displays the city name according to the state selected
    Private Sub GetStateCity(ByVal intaddrS As Integer)
        Dim dtstate As New DataTable
        Try
            dtstate = DAddress.GetStateCity(intaddrS, cmbCountry.SelectedValue)
            blnCityFlag = False
            BCommon.SetComboValues(cmbCity, dtstate, "CityCD", "Description")
            blnCityFlag = True
            If cmbCity.Items.Count > 0 Then
                If ConfigurationManager.AppSettings("Country") = cmbCountry.SelectedValue And ConfigurationManager.AppSettings("State") = cmbState.SelectedValue Then cmbCity.SelectedValue = ConfigurationManager.AppSettings("City")
            Else
                cmbCity.Text = ""
                txtPinCode.Text = ""
            End If
            cmbCity.Refresh()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetStateCity")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    '   Displays the pincode of the corresponding city
    Private Sub GetCityPincode(ByVal intaddrci As Integer)
        Dim intpincode As Integer
        Try
            intpincode = DAddress.GetCityPinCode(intaddrci)
            txtPinCode.Text = intpincode
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "GetCityPincode")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub frmDoctor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Not (ConfigurationManager.AppSettings("FormMode") = "R") Then
                If isUpdate() Then
                    Select Case BCommon.ShowMsgError(10081, "YNC")
                        Case Windows.Forms.DialogResult.Yes
                            Call SaveData()
                        Case Windows.Forms.DialogResult.Cancel
                            e.Cancel = True
                        Case Windows.Forms.DialogResult.No
                    End Select
                End If
                Me.Cursor = Cursors.Default
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "frmDoctor_FormClosing")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub frmDoctor_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        'Rauhl_ITS@20073012 : Add following code display help
        Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Doctor")
        e.Cancel = True
    End Sub

    Private Sub frmDoctor_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        'Rauhl_ITS@20073012 : Add following code display help
        If e.KeyCode = Keys.F1 Then
            e.SuppressKeyPress = True
            Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Doctor")
        End If
    End Sub

    Private Sub frmDoctor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Call BCommon.SetFormStandards(Me)
            DisplayData()
            ReDim address(cmbAddrType.Items.Count)
            ReDim updtAddress(cmbAddrType.Items.Count)
            intAddress = 0
            blnFlagAddType = True
            blnCountryFlag = True
            blnStateFlag = True
            blnCityFlag = True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "frmDoctor_Load")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmbHospName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbHospName.SelectedIndexChanged
        Try
            If IsNothing(cmbHospName.SelectedValue) = False Then
                txtShortName.Text = cmbHospName.DataSource.Rows(cmbHospName.SelectedIndex).Item(2)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cmbHospName_SelectedIndexChanged")
            Me.Cursor = Cursors.Default
        End Try

    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim form As New frmMasterBrowse
            form.strSearch = "Doctor"
            'Rahul_ITS@20072612
            '<<START
            form.StartPosition = FormStartPosition.Manual
            form.Height = MDIPharmacy.MdiScaleHeight
            form.Width = MDIPharmacy.MdiScaleWidth
            Dim pt As New Point
            pt.Y = ((MDIPharmacy.MdiScaleHeight - form.Height) / 2) + MDIPharmacy.pnlHeading.Height + MDIPharmacy.MenuStrip.Height
            pt.X = (MDIPharmacy.MdiScaleWidth - form.Width) / 2
            form.Location = pt
            form.ShowInTaskbar = False
            '>>END
            form.ShowDialog()
            _intDoctorID = form.strRecordNo
            Call ClearData()
            If _intDoctorID <> 0 Then
                Call ViewDoctor()
                btnSave.Text = "&Update"
                If ConfigurationManager.AppSettings("FormMode") = "R" Then
                    btnDelete.Enabled = False
                Else
                    btnDelete.Enabled = True
                End If
            End If
            Call SetcontrolTag()
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSearch_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Dispalys the Doctor Information
    Private Sub ViewDoctor()
        Dim dtsDoctor As New DataSet
        Try
            dtsDoctor = DDoctor.GetDoctor(_intDoctorID)
            If dtsDoctor.Tables(0).Rows.Count > 0 Then
                With dtsDoctor.Tables(0).Rows(0)
                    txtDoctorID.Text = .Item(0)
                    txtDoctorID.Tag = .Item(0)
                    cmbQual.SelectedValue = .Item(1)
                    cmbQual.Tag = .Item(1)
                    'cmbRefType.SelectedValue = Replace(.Item(2), "", " ")
                    'cmbRefType.SelectedValue = IIf(.Item(2) = "", " ", .Item(2))
                    'cmbRefType.Tag = IIf(.Item(2) = "", " ", .Item(2))
                    cmbRefType.SelectedValue = .Item(2)
                    cmbRefType.Tag = .Item(2)
                    txtRefAmt.Text = .Item(3)
                    txtRefAmt.Tag = .Item(3)
                    cmbHospName.SelectedValue = .Item(5)
                    cmbHospName.Tag = .Item(5)
                    txtShortName.Tag = txtShortName.Text
                    CMBSPECIAL.SelectedValue = .Item(6)
                    CMBSPECIAL.Tag = .Item(6)
                    txtDrDispName.Text = .Item(7)
                    txtDrDispName.Tag = .Item(7)
                    Call ViewPerson(.Item(4))
                    Call ViewAddress(.Item(4))
                End With
            Else
                'need 2 b changed
                BCommon.ShowMsgError(10082)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ViewDoctor")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmbCountry_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCountry.SelectedIndexChanged
        If blnCountryFlag = False Then Me.Cursor = Cursors.Default : Exit Sub
        Call GetCountryState()
    End Sub

    Private Sub cmbState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbState.SelectedIndexChanged
        If blnStateFlag = False Then Me.Cursor = Cursors.Default : Exit Sub
        Call GetStateCity(cmbState.SelectedValue)
    End Sub

    Private Sub cmbCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCity.SelectedIndexChanged
        If blnCityFlag = False Then Me.Cursor = Cursors.Default : Exit Sub
        If cmbCity.Items.Count > 0 Then
            Call GetCityPincode(cmbCity.SelectedValue)
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Call ClearData()
            Call SetcontrolTag()
            If btnSave.Text = "&Update" Then
                btnSave.Text = "&Save"
                btnDelete.Enabled = False
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnCancel_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtFname_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtFname.LostFocus
        Try
            txtFname.Text = IIf(Trim(txtFname.Text) = "", txtFname.Tag, Trim(txtFname.Text))
            If txtFname.Text <> "" Or txtFname.Text <> txtFname.Tag Then
                txtFname.Text = UCase(Mid(txtFname.Text, 1, 1)) & Mid(txtFname.Text, 2)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtFname_LostFocus")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtMname_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMname.LostFocus
        Try
            txtMname.Text = IIf(Trim(txtMname.Text) = "", txtMname.Tag, Trim(txtMname.Text))
            If txtMname.Text <> "" Or txtMname.Text <> txtFname.Tag Then
                txtMname.Text = UCase(Mid(txtMname.Text, 1, 1)) & Mid(txtMname.Text, 2)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtMname_LostFocus")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtLname_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLname.LostFocus
        Try
            txtLname.Text = IIf(Trim(txtLname.Text) = "", txtLname.Tag, Trim(txtLname.Text))
            If txtLname.Text <> "" Or txtLname.Text <> txtFname.Tag Then
                txtLname.Text = UCase(Mid(txtLname.Text, 1, 1)) & Mid(txtLname.Text, 2)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtLname_LostFocus")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtRefAmt_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRefAmt.KeyUp
        Try
            If (BCommon.IsInteger(txtRefAmt.Text) = False) Then txtRefAmt.Focus() : txtRefAmt.Text = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtRefAmt_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtRefAmt_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRefAmt.LostFocus
        Try
            If cmbRefType.SelectedValue = "P" Then
                If CDbl(txtRefAmt.Text) >= 100 Then
                    BCommon.ShowMsgError(10083)
                    txtRefAmt.Text = ""
                    txtRefAmt.Focus()
                End If
            End If
            If txtRefAmt.Text <> "" And IsNumeric(txtRefAmt.Text) Then txtRefAmt.Text = Format(CDbl(txtRefAmt.Text), ".00")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtRefAmt_LostFocus")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Checks for Updation of information
    Private Function isUpdate() As Boolean
        'Dim blndata As New Boolean
        'Dim intc As New Integer
        Try
            If Trim(txtFname.Text) <> Trim(txtFname.Tag) _
            Or Trim(txtMname.Text) <> Trim(txtMname.Tag) Or Trim(txtLname.Text) <> Trim(txtLname.Tag) _
            Or Trim(cmbRefType.Text) <> Trim(cmbRefType.Tag) _
            Or Trim(cmbTitle.Text) <> Trim(cmbTitle.Tag) _
            Or Trim(cmbQual.Text) <> Trim(cmbQual.Tag) _
            Or Trim(txtDrDispName.Text) <> Trim(txtDrDispName.Tag) _
            Or Trim(txtRefAmt.Text) <> Trim(txtRefAmt.Tag) Or Trim(cmbHospName.Text) <> Trim(cmbHospName.Tag) _
            Or Trim(txtShortName.Text) <> Trim(txtShortName.Tag) Or CMBSPECIAL.Text <> Trim(CMBSPECIAL.Tag) Then
                Return True
            Else
                Return isEqual()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isUpdate")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    'Checks for Updation on the address ingformation
    Private Function isEqual() As Boolean
        'Dim intcount As Integer = 0
        Dim intc As New Integer
        Try
            For intc = 0 To address.Length - 1
                If IsNothing(address(intc)) Then Continue For
                If IsNothing(updtAddress(intc)) Then Me.Cursor = Cursors.Default : Return True : Exit Function
                With address(intc)
                    If updtAddress(intc).City <> .City Or updtAddress(intc).Country <> .Country Or _
                    updtAddress(intc).Description1 <> .Description1 Or updtAddress(intc).Description2 <> .Description2 Or _
                    updtAddress(intc).State <> .State Or updtAddress(intc).PhoneNo1 <> .PhoneNo1 Or _
                    updtAddress(intc).PhoneNo2 <> .PhoneNo2 Or updtAddress(intc).PinCode <> .PinCode Or _
                    updtAddress(intc).EmailID <> .EmailID Or updtAddress(intc).WebSiteAddress <> .WebSiteAddress Then
                        Me.Cursor = Cursors.Default
                        Return True
                        Exit Function
                    End If
                End With
            Next
            Return False
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isEqual")
            Me.Cursor = Cursors.Default
            Return False
        End Try
    End Function

    'Private Sub cmbRefType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbRefType.SelectedIndexChanged
    '    If cmbRefType.SelectedValue.ToString = "A" Then
    '        lblPercent.Text = ConfigurationManager.AppSettings("Currency")
    '    Else
    '        lblPercent.Text = "%"
    '    End If
    'End Sub

    Private Function isAddressChanged() As Byte
        Try
            If txtAddr1.Text <> txtAddr1.Tag Or Trim(txtPinCode.Text) <> _
            txtPinCode.Tag Or Trim(txtPhone1.Text) <> txtPhone1.Tag Or Trim(txtPhone2.Text) <> txtPhone2.Tag Or txtFax.Text _
            <> txtFax.Tag Or Trim(txtEmail.Text) <> txtEmail.Tag Or Trim(txtWebSite.Text) <> txtWebSite.Tag Then
                Return 1
            Else
                Return 0
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isAddressChanged")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    Private Sub txtDoctorID_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDoctorID.KeyDown
        Try
            'Rahul_ITS@20071113 : Add following line
            If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
            If e.KeyCode = Keys.Enter Then
                cmbAddrType.Focus()
            Else
                If BCommon.ValidateText(e.KeyCode, "ALF", False) = False Then
                    e.SuppressKeyPress = True
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "txtDoctorID_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub CMBSPECIAL_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles CMBSPECIAL.KeyDown
        If e.Alt Then Me.Cursor = Cursors.Default : Exit Sub
        If e.KeyCode = Keys.Enter Then cmbRefType.Focus()
    End Sub

    Private Sub SetcontrolTag()
        Try
            txtFname.Tag = txtFname.Text
            txtMname.Tag = txtMname.Text
            txtLname.Tag = txtLname.Text
            cmbTitle.Tag = cmbTitle.Text
            cmbQual.Tag = cmbQual.Text
            cmbRefType.Tag = cmbRefType.Text
            cmbHospName.Tag = cmbHospName.Text
            CMBSPECIAL.Tag = CMBSPECIAL.Text
            txtRefAmt.Tag = txtRefAmt.Text
            txtShortName.Tag = txtShortName.Text
            txtDrDispName.Tag = txtDrDispName.Text
            cmbAddrType.Tag = cmbAddrType.Text
            cmbCountry.Tag = cmbCountry.Text
            cmbState.Tag = cmbState.Text
            cmbCity.Tag = cmbCity.Text
            txtAddr1.Tag = txtAddr1.Text
            txtPinCode.Tag = txtPinCode.Text
            txtPhone1.Tag = txtPhone1.Text
            txtPhone2.Tag = txtPhone2.Text
            txtFax.Tag = txtFax.Text
            txtEmail.Tag = txtEmail.Text
            txtWebSite.Tag = txtWebSite.Text
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SetcontrolTag")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            If (DDoctor.IsDoctorUsed(_intDoctorID)) = 0 Then
                If (DDoctor.DeleteDoctor(_intDoctorID)) > 0 Then
                    BCommon.ShowMsgError(10359)
                    txtFname.Focus()
                    Call ClearData()
                    If btnSave.Text = "&Update" Then btnSave.Text = "&Save"
                    btnDelete.Enabled = False
                End If
            Else
                BCommon.ShowMsgError(10358)
                btnDelete.Focus()
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnDelete_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
End Class